\hypertarget{driver__unit__v2_2main_8c}{
\section{driver\_\-unit\_\-v2/main.c File Reference}
\label{driver__unit__v2_2main_8c}\index{driver\_\-unit\_\-v2/main.c@{driver\_\-unit\_\-v2/main.c}}
}
Main file of the driver unit.  


{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$avr/io.h$>$}\par
{\tt \#include $<$avr/interrupt.h$>$}\par
{\tt \#include \char`\"{}main.h\char`\"{}}\par
{\tt \#include \char`\"{}board.h\char`\"{}}\par
{\tt \#include \char`\"{}init.h\char`\"{}}\par
{\tt \#include \char`\"{}../i2c.h\char`\"{}}\par
{\tt \#include \char`\"{}../delay.h\char`\"{}}\par
{\tt \#include \char`\"{}../wmv\_\-bus/bus.h\char`\"{}}\par
{\tt \#include \char`\"{}../wmv\_\-bus/bus\_\-ping.h\char`\"{}}\par
{\tt \#include \char`\"{}../wmv\_\-bus/bus\_\-rx\_\-queue.h\char`\"{}}\par
{\tt \#include \char`\"{}../wmv\_\-bus/bus\_\-tx\_\-queue.h\char`\"{}}\par
{\tt \#include \char`\"{}../wmv\_\-bus/bus\_\-commands.h\char`\"{}}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\hypertarget{driver__unit__v2_2main_8c_e2b7e3b6edd684fbb9a22a6389c6737b}{
\#define \hyperlink{driver__unit__v2_2main_8c_e2b7e3b6edd684fbb9a22a6389c6737b}{LM76\_\-ADDR}~0x90}
\label{driver__unit__v2_2main_8c_e2b7e3b6edd684fbb9a22a6389c6737b}

\begin{CompactList}\small\item\em The address of the LM76 temperature sensor connected to the I2C bus. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{driver__unit__v2_2main_8c_5b4e38c0ce71722f23b9cd8b82f6434e}{activate\_\-output} (unsigned char from\_\-addr, unsigned char index, unsigned char type)
\begin{CompactList}\small\item\em Activate a driver output This function is used to activate an output on the driver unit. It will remember which device that sent the request for an activation so that the driver\_\-unit will remember it when that device goes offline so it can shut the outputs off. \item\end{CompactList}\item 
void \hyperlink{driver__unit__v2_2main_8c_7a1f49ff35cec91585cfbea4c4f336f7}{deactivate\_\-output} (unsigned char from\_\-addr, unsigned char index)
\begin{CompactList}\small\item\em Deactivate a driver output This function is used to deactivate an output on the driver unit. It will remember which device that sent the request for an deactivation so that the driver\_\-unit will remember it when that device goes offline so it can shut the outputs off. \item\end{CompactList}\item 
unsigned int \hyperlink{driver__unit__v2_2main_8c_0c07bb6409785ca3e7ddf8c74ad9441a}{lm76\_\-get\_\-temp} (void)
\begin{CompactList}\small\item\em Retrieve the temperature from the LM76 sensor This function is used to retrieve the temperature from the LM76 sensor that does exist on the driver\_\-unit. \item\end{CompactList}\item 
\hypertarget{driver__unit__v2_2main_8c_e215e459098d842339b421dfc696989a}{
void \hyperlink{driver__unit__v2_2main_8c_e215e459098d842339b421dfc696989a}{bus\_\-parse\_\-message} (void)}
\label{driver__unit__v2_2main_8c_e215e459098d842339b421dfc696989a}

\begin{CompactList}\small\item\em Parse a message and exectute the proper commands This function is used to parse a message that was receieved on the bus that is located in the RX queue. \item\end{CompactList}\item 
unsigned char \hyperlink{driver__unit__v2_2main_8c_d9e4e537759b32f2e6c232282b310677}{read\_\-ext\_\-addr} (void)
\begin{CompactList}\small\item\em Read the external DIP-switch. This function is used to read the external offset address on the driver\_\-unit. \item\end{CompactList}\item 
\hypertarget{driver__unit__v2_2main_8c_6da085465ff4bc2f090453a8bf72f931}{
void \hyperlink{driver__unit__v2_2main_8c_6da085465ff4bc2f090453a8bf72f931}{set\_\-ptt\_\-led\_\-status} (unsigned char state)}
\label{driver__unit__v2_2main_8c_6da085465ff4bc2f090453a8bf72f931}

\begin{CompactList}\small\item\em Set the PTT led status. \item\end{CompactList}\item 
unsigned char \hyperlink{driver__unit__v2_2main_8c_08ce08946ccdeede7ed6efac79231508}{get\_\-ptt\_\-status} (void)
\begin{CompactList}\small\item\em Check the status of the external PTT lines. \item\end{CompactList}\item 
int \hyperlink{driver__unit__v2_2main_8c_840291bc02cba5474a4cb46a9b9566fe}{main} (void)
\item 
\hypertarget{driver__unit__v2_2main_8c_6761d1f0a3be0ccdce714cb9c7cbdcc3}{
\hyperlink{driver__unit__v2_2main_8c_6761d1f0a3be0ccdce714cb9c7cbdcc3}{ISR} (SIG\_\-OUTPUT\_\-COMPARE0)}
\label{driver__unit__v2_2main_8c_6761d1f0a3be0ccdce714cb9c7cbdcc3}

\begin{CompactList}\small\item\em Output compare 0 interrupt - \char`\"{}called\char`\"{} with 1ms intervals. \item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
\hypertarget{driver__unit__v2_2main_8c_f6c8a57664747c58a8c7361bbaef1281}{
unsigned char \hyperlink{driver__unit__v2_2main_8c_f6c8a57664747c58a8c7361bbaef1281}{device\_\-id}}
\label{driver__unit__v2_2main_8c_f6c8a57664747c58a8c7361bbaef1281}

\begin{CompactList}\small\item\em Contains info if the module is a positive or negative driver. \item\end{CompactList}\item 
\hypertarget{driver__unit__v2_2main_8c_9bd329ffa7a65c7d00d6a2428b854be0}{
\hyperlink{structdriver__status__struct}{driver\_\-status\_\-struct} \hyperlink{driver__unit__v2_2main_8c_9bd329ffa7a65c7d00d6a2428b854be0}{driver\_\-status}}
\label{driver__unit__v2_2main_8c_9bd329ffa7a65c7d00d6a2428b854be0}

\begin{CompactList}\small\item\em A status structure of the driver unit outputs. \item\end{CompactList}\item 
\hypertarget{driver__unit__v2_2main_8c_f9cecdd922128d66e61541bac7dd6a56}{
unsigned int \hyperlink{driver__unit__v2_2main_8c_f9cecdd922128d66e61541bac7dd6a56}{counter\_\-compare0} = 0}
\label{driver__unit__v2_2main_8c_f9cecdd922128d66e61541bac7dd6a56}

\begin{CompactList}\small\item\em Counter to keep track of the numbers of ticks from timer0. \item\end{CompactList}\item 
\hypertarget{driver__unit__v2_2main_8c_74878c125411662a50fddaae20fef5fc}{
unsigned int \hyperlink{driver__unit__v2_2main_8c_74878c125411662a50fddaae20fef5fc}{counter\_\-sync} = 0}
\label{driver__unit__v2_2main_8c_74878c125411662a50fddaae20fef5fc}

\begin{CompactList}\small\item\em Counter to keep track of the time elapsed since the last sync message was sent. \item\end{CompactList}\item 
\hypertarget{driver__unit__v2_2main_8c_358c5643835429082b4aeea9c0365896}{
unsigned int \hyperlink{driver__unit__v2_2main_8c_358c5643835429082b4aeea9c0365896}{counter\_\-ping\_\-interval} = 0}
\label{driver__unit__v2_2main_8c_358c5643835429082b4aeea9c0365896}

\begin{CompactList}\small\item\em Counter to keep track of when to send a ping out on the bus. \item\end{CompactList}\item 
\hypertarget{driver__unit__v2_2main_8c_f516c2076f185d7a0882a279590496e0}{
unsigned char \hyperlink{driver__unit__v2_2main_8c_f516c2076f185d7a0882a279590496e0}{check\_\-ptt\_\-status} = 0}
\label{driver__unit__v2_2main_8c_f516c2076f185d7a0882a279590496e0}

\begin{CompactList}\small\item\em Flag which is set when we wish to poll the PTT status. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Main file of the driver unit. 

\begin{Desc}
\item[Author:]Mikael Larsmark, SM2WMV \end{Desc}
\begin{Desc}
\item[Date:]2009-03-16 

\begin{Code}\begin{verbatim} #include "driver_unit_v2/main.c" 
\end{verbatim}
\end{Code}

 \end{Desc}


Definition in file \hyperlink{driver__unit__v2_2main_8c-source}{main.c}.

\subsection{Function Documentation}
\hypertarget{driver__unit__v2_2main_8c_5b4e38c0ce71722f23b9cd8b82f6434e}{
\index{driver\_\-unit\_\-v2/main.c@{driver\_\-unit\_\-v2/main.c}!activate\_\-output@{activate\_\-output}}
\index{activate\_\-output@{activate\_\-output}!driver_unit_v2/main.c@{driver\_\-unit\_\-v2/main.c}}
\subsubsection[{activate\_\-output}]{\setlength{\rightskip}{0pt plus 5cm}void activate\_\-output (unsigned char {\em from\_\-addr}, \/  unsigned char {\em index}, \/  unsigned char {\em type})}}
\label{driver__unit__v2_2main_8c_5b4e38c0ce71722f23b9cd8b82f6434e}


Activate a driver output This function is used to activate an output on the driver unit. It will remember which device that sent the request for an activation so that the driver\_\-unit will remember it when that device goes offline so it can shut the outputs off. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em from\_\-addr}]The device that sent the request of activating an output \item[{\em index}]The index of which output to activate \item[{\em type}]The type of output this is, usually is the bus command \end{description}
\end{Desc}


Definition at line 67 of file main.c.

References driver\_\-status\_\-struct::driver\_\-output\_\-owner, driver\_\-status\_\-struct::driver\_\-output\_\-state, and driver\_\-status\_\-struct::driver\_\-output\_\-type.\hypertarget{driver__unit__v2_2main_8c_7a1f49ff35cec91585cfbea4c4f336f7}{
\index{driver\_\-unit\_\-v2/main.c@{driver\_\-unit\_\-v2/main.c}!deactivate\_\-output@{deactivate\_\-output}}
\index{deactivate\_\-output@{deactivate\_\-output}!driver_unit_v2/main.c@{driver\_\-unit\_\-v2/main.c}}
\subsubsection[{deactivate\_\-output}]{\setlength{\rightskip}{0pt plus 5cm}void deactivate\_\-output (unsigned char {\em from\_\-addr}, \/  unsigned char {\em index})}}
\label{driver__unit__v2_2main_8c_7a1f49ff35cec91585cfbea4c4f336f7}


Deactivate a driver output This function is used to deactivate an output on the driver unit. It will remember which device that sent the request for an deactivation so that the driver\_\-unit will remember it when that device goes offline so it can shut the outputs off. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em from\_\-addr}]The device that sent the request of deactivating the output \item[{\em index}]The index of which output to deactivate \end{description}
\end{Desc}


Definition at line 125 of file main.c.

References driver\_\-status\_\-struct::driver\_\-output\_\-owner, driver\_\-status\_\-struct::driver\_\-output\_\-state, and driver\_\-status\_\-struct::driver\_\-output\_\-type.\hypertarget{driver__unit__v2_2main_8c_08ce08946ccdeede7ed6efac79231508}{
\index{driver\_\-unit\_\-v2/main.c@{driver\_\-unit\_\-v2/main.c}!get\_\-ptt\_\-status@{get\_\-ptt\_\-status}}
\index{get\_\-ptt\_\-status@{get\_\-ptt\_\-status}!driver_unit_v2/main.c@{driver\_\-unit\_\-v2/main.c}}
\subsubsection[{get\_\-ptt\_\-status}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char get\_\-ptt\_\-status (void)}}
\label{driver__unit__v2_2main_8c_08ce08946ccdeede7ed6efac79231508}


Check the status of the external PTT lines. 

\begin{Desc}
\item[Returns:]A byte which contains info of the state of the PTT lines. 0 = R1, 1 = R2 etc \end{Desc}


Definition at line 364 of file main.c.

References status.

Referenced by main().\hypertarget{driver__unit__v2_2main_8c_0c07bb6409785ca3e7ddf8c74ad9441a}{
\index{driver\_\-unit\_\-v2/main.c@{driver\_\-unit\_\-v2/main.c}!lm76\_\-get\_\-temp@{lm76\_\-get\_\-temp}}
\index{lm76\_\-get\_\-temp@{lm76\_\-get\_\-temp}!driver_unit_v2/main.c@{driver\_\-unit\_\-v2/main.c}}
\subsubsection[{lm76\_\-get\_\-temp}]{\setlength{\rightskip}{0pt plus 5cm}unsigned int lm76\_\-get\_\-temp (void)}}
\label{driver__unit__v2_2main_8c_0c07bb6409785ca3e7ddf8c74ad9441a}


Retrieve the temperature from the LM76 sensor This function is used to retrieve the temperature from the LM76 sensor that does exist on the driver\_\-unit. 

\begin{Desc}
\item[Returns:]The temperature but not in float format \end{Desc}


Definition at line 180 of file main.c.

References i2cMasterReceiveNI(), and LM76\_\-ADDR.\hypertarget{driver__unit__v2_2main_8c_840291bc02cba5474a4cb46a9b9566fe}{
\index{driver\_\-unit\_\-v2/main.c@{driver\_\-unit\_\-v2/main.c}!main@{main}}
\index{main@{main}!driver_unit_v2/main.c@{driver\_\-unit\_\-v2/main.c}}
\subsubsection[{main}]{\setlength{\rightskip}{0pt plus 5cm}int main (void)}}
\label{driver__unit__v2_2main_8c_840291bc02cba5474a4cb46a9b9566fe}


Main function of the driver unit 

Definition at line 380 of file main.c.

References bus\_\-add\_\-tx\_\-message(), bus\_\-allowed\_\-to\_\-send(), BUS\_\-BROADCAST\_\-ADDR, bus\_\-check\_\-tx\_\-status(), BUS\_\-CMD\_\-PING, BUS\_\-CMD\_\-SYNC, BUS\_\-DEVICE\_\-STATUS\_\-MESSAGE\_\-INTERVAL, bus\_\-get\_\-address(), bus\_\-get\_\-device\_\-count(), bus\_\-init(), bus\_\-is\_\-master(), BUS\_\-MASTER\_\-SYNC\_\-INTERVAL, bus\_\-parse\_\-message(), bus\_\-set\_\-address(), bus\_\-set\_\-is\_\-master(), check\_\-ptt\_\-status, counter\_\-ping\_\-interval, counter\_\-sync, deactivate\_\-output(), DEF\_\-NR\_\-DEVICES, device\_\-count, device\_\-id, DEVICE\_\-ID\_\-DRIVER\_\-NEG, DEVICE\_\-ID\_\-DRIVER\_\-POS, driver\_\-status\_\-struct::driver\_\-output\_\-state, get\_\-ptt\_\-status(), init\_\-ports(), init\_\-timer\_\-0(), init\_\-timer\_\-2(), read\_\-ext\_\-addr(), rx\_\-queue\_\-is\_\-empty(), set\_\-ptt\_\-led\_\-status(), and tx\_\-queue\_\-is\_\-empty().\hypertarget{driver__unit__v2_2main_8c_d9e4e537759b32f2e6c232282b310677}{
\index{driver\_\-unit\_\-v2/main.c@{driver\_\-unit\_\-v2/main.c}!read\_\-ext\_\-addr@{read\_\-ext\_\-addr}}
\index{read\_\-ext\_\-addr@{read\_\-ext\_\-addr}!driver_unit_v2/main.c@{driver\_\-unit\_\-v2/main.c}}
\subsubsection[{read\_\-ext\_\-addr}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char read\_\-ext\_\-addr (void)}}
\label{driver__unit__v2_2main_8c_d9e4e537759b32f2e6c232282b310677}


Read the external DIP-switch. This function is used to read the external offset address on the driver\_\-unit. 

\begin{Desc}
\item[Returns:]The address of the external DIP-switch \end{Desc}


Definition at line 352 of file main.c.